//
// Created by Tony on 2024/7/2.
//

#ifndef PARSER_METHOD_DEFINE_H
#define PARSER_METHOD_DEFINE_H

#include "../../AstList.h"
#include "../../leaf/Name.h"
#include "../../list/function/ParameterList.h"
#include "../AccessFlags.h"
#include "../TypeTag.h"

namespace Parser {

class MethodDefine final : public AstList {
    string nodeName;
    shared_ptr<Compiler::SymbolTable> mSymbolTable;

public:
    explicit MethodDefine(const vector<shared_ptr<Ast>>& children) : AstList(children) {
        nodeName = __func__;
    }

    shared_ptr<AccessFlags> getAccessFlags() {
        return static_pointer_cast<AccessFlags>(children[0]);
    }

    string getName() { return static_pointer_cast<Name>(children[1])->name(); }

    shared_ptr<ParameterList> getParameterList() {
        return static_pointer_cast<ParameterList>(children[2]);
    }

    shared_ptr<TypeTag> getReturnTypeTag() { return static_pointer_cast<TypeTag>(children[3]); }

    shared_ptr<Ast> getBody() { return children[4]; }

    void setSymbolTable(const shared_ptr<Compiler::SymbolTable>& symbolTable) {
        mSymbolTable = symbolTable;
    }

    shared_ptr<Compiler::SymbolTable> getSymbolTable() { return mSymbolTable; }

    int32_t accept(Compiler::Visitor* visitor) override;
};

} // namespace Parser

#endif // PARSER_METHOD_DEFINE_H
